﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace V32Assembler
{
    public enum ArgSize { Byte = 1, Word = 4 }

    public abstract class Number
    {
        public abstract ArgSize Size { get; }

        public abstract byte[] Bytes { get; }
        public abstract uint NumBytes { get; }
    }

    public class BaseNumber : Number
    {
        public uint WordVal { get; private set; }

        public BaseNumber() : this(0) { }

        public BaseNumber(uint baseVal)
        {
            WordVal = baseVal;
        }

        public override ArgSize Size
        {
            get
            {
                return ArgSize.Word;
            }
        }
        public override byte[] Bytes
        {
            get
            {
                return WordVal.ToBytes();
            }
        }
        public override uint NumBytes
        {
            get
            {
                return (uint)ArgSize.Word;
            }
        }

        public override string ToString()
        {
            return WordVal.ToString();
        }
    }

    public class OffsetNumber : Number
    {
        public ArgSize ConstSize { get; private set; }
        public byte ByteVal { get; private set; }
        public uint WordVal { get; private set; }

        public OffsetNumber() : this(0, true) { }

        public OffsetNumber(uint offsetVal, bool isByte)
        {
            ConstSize = isByte ? ArgSize.Byte : ArgSize.Word;
            ByteVal = (byte)offsetVal;
            WordVal = offsetVal;
        }
        public OffsetNumber Negate()
        {
            ConstSize = ArgSize.Word;
            WordVal = ~WordVal + 1;
            return this;
        }

        public override ArgSize Size
        {
            get
            {
                return ConstSize;
            }
        }
        public override byte[] Bytes
        {
            get
            {
                if (ConstSize == ArgSize.Word)
                    return WordVal.ToBytes();
                else return new byte[] { ByteVal };
            }
        }
        public override uint NumBytes
        {
            get
            {
                return (uint)ConstSize;
            }
        }

        public override string ToString()
        {
            return ConstSize == ArgSize.Byte ? ByteVal.ToString() : WordVal.ToString();
        }
    }
}
